<div align="left">&nbsp;<b><?=translate('title');?></b><br><br></div>
<?
include('wallet_db.html');
$manual_upgrades_info=translate('manual_upgrades_info');
$select_user=translate('select_user');
$select_type=translate('select_type');
//$message_upgr_success=translate('message_upgr_success');
$no_clients=translate('no_clients');

if (isset($upgr_succ) && $upgr_succ=='yes') {
	 $okMsg = translate('$message_upgr_success');
	 include_once('okMsg.html');
}
//echo "<p>$message_upgr_success</p>";

$params[sid] = $sid;
$params[action] = "manualUpgrades";
$url = "$baseURL/$webDIR/?".encode_params($params);

$params[sid] = $sid;
$params[action] = "manualUpgrades";
$params[upgr_succ] = "yes";
$urla = "$baseURL/$webDIR/?".encode_params($params);

if (!isset($hid_var) && empty($_POST)) {
	//-----------------------------------------------------
	$sql['type'] = "SELECT";
	$sql['params'] = "client_id, username, firstname, lastname, blocked";
	$sql['table'] = "clients";
	$sql['where'] = "reseller_id='$id'";
	$sql['options'] = "ORDER BY username";
	$sql['return'] = "struct";
	//------------------------------------------------------
	if (!$result=sql_exec($sql,$dbh81,'assoc')) {
		 	$errorMsg = translate('$no_clients');
			#include_once('errorMsg.html');
			#exit;
		exit($no_clients);
	}
	foreach ($result as $value) {
		$clients[$value[client_id]]=$value[username];
	}
	echo "<form action='$url' method='POST'>
		<div align=left><p>$manual_upgrades_info</p>
		$select_user:&nbsp;<select name='client_id'>
		<option value=0>----------</option>\n";
		echo "<optgroup label='Active'>";
      foreach ($result as $key => $val) {
      	if ($val['blocked'] == 0) {
      		echo "<option value='".$val['client_id']."'>".$val['username']."</option>\n";
      	}
      }
      echo "</optgroup>
      <optgroup label='Suspended (traffic)'>";
      unset($key,$val);
      foreach ($result as $key => $val) {
      	if ($val['blocked'] == 2) {
      		echo "<option value='".$val['client_id']."'>".$val['username']."</option>\n";
      	}
      }
      echo "</optgroup>
      <optgroup label='Suspended (expired)'>";
      unset($key,$val);
      foreach ($result as $key => $val) {
      	if ($val['blocked'] == 3) {
      		echo "<option value='".$val['client_id']."'>".$val['username']."</option>\n";
      	}
      }
	echo "</select>&nbsp;$select_type:&nbsp;
		<select name=type>
			<option value=0>---------</option>
			<option value='renewal'>renewal</option>
			<option value='services'>services</services>
			<option value='plan'>plan</option>
		</select>&nbsp;
		<input type=submit name=submit value='go $show_client'>
		<input type=hidden name=return_url value='$urla'>
		<input type='hidden' name='hid_var' value='345'></form></div>";
} else {

	#$client_id=$_REQUEST[client_id];

	// sve: fix (03-03-2006 1:45am)
	if (!empty($_POST['username'])) {
          $sql['type'] = "SELECT";
          $sql['params'] = "client_id";
          $sql['table'] = "clients";
          $sql['where'] = "username='".pg_escape_string($_POST['username'])."'";
          $sql['options'] = "";
          $sql['return'] = "struct";

          if (!$result=sql_exec($sql,$dbh81,'assoc')) {
                  $errorMsg = translate('int_error');
                  include_once('errorMsg.html');
                  exit;
          }
          $client_id = $result[0]['client_id'];
  }
  // end: fix

        $sql['type'] = "SELECT";
        $sql['params'] = "username";
        $sql['table'] = "clients";
        $sql['where'] = "client_id='$client_id'";
        $sql['options'] = "";
        $sql['return'] = "struct";
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$dbh81,'assoc')) {
					 		$errorMsg = translate('int_error');
							include_once('errorMsg.html');
							exit;
//                exit('ERROR1');
        }

	$username=$result[0][username];

        //------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='a.username, a.firstname, a.lastname, a.server, b.db_user, b.db_host, b.db_pass, b.db_name';
        $sql['table']='clients as a, servers as b';
        $sql['where']="a.client_id='$client_id' and a.server=b.name";
        $sql['options']='';
        $sql['return']='struct';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$dbh81,'assoc')) {
					    $errorMsg = translate('upg_error');
							include_once('errorMsg.html');
							exit;
//                exit("$upg_error");
        }
        $serv_info=$result[0];

        $ph_dbuser=$serv_info[db_user];
        $ph_dbhost=$serv_info[db_host];
        $ph_dbpass=$serv_info[db_pass];
        $ph_dbname=$serv_info[db_name];
        $ph_dbh = @pg_connect("dbname=".$ph_dbname." host=".$ph_dbhost." user=".$ph_dbuser." password=".$ph_dbpass."");
        if (!$ph_dbh) {
					    $errorMsg = translate('upg_error');
							include_once('errorMsg.html');
							exit;
        }
        //------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='expire_date';
        $sql['table']='plans';
        $sql['where']="user_id='$client_id'";
        $sql['options']='';
        $sql['return']='struct';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$ph_dbh,'assoc')) {
					    $errorMsg = translate('upg_error');
							include_once('errorMsg.html');
							exit;
        }
        $data[expiration_date]=$result[0][expire_date];
	#}
	$url1='https://supremeserver1.com/resellers/u/upgrade/upgrade.php?';
	$data[type]=$_REQUEST[type];
	$data[action] = $_POST[type];
	$data[username]=$username;
	#$data[return_url]="$urla";
	$data[return_url]='';
	$data[reseller_authenticated]="yes";
	if (isset($_POST[action])) {
		$data=array_merge($_GET,$_POST);
		$data[reseller_authenticated]="yes";
		$data[wal_proc]='yes';
	}
	if (!isset($_REQUEST['returnURL'])) {
		$data[returnURL]="$urla";
	} else {
		$data['returnURL'] = $_REQUEST['returnURL'];
	}
	if(is_array($data)){
	        while(list($k,$v) = each($data)){
	                if($v){
	                        if(is_array($v)){
	                                while(list($k1,$v1) =each($v)){
	                                         if($v1) $options .= "&$k"."[".$k1."]=".urlencode($v1);
	                                }
	                        }else {
	                                $options .= "&$k=".urlencode($v);
	                        }
	                }
	        }
	        $url1 = $url1.$options;
	}
	if (is_me()) echo "<br><br>$url1<br>";
	include($url1);
}
?>